<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('项目详情')" />
    <th:block th:include="include :: select2-css" />
</head>

<body>
<div class="main-content">
    <form id="form-user-edit" class="form-horizontal" th:object="${basStock}">
        <input name="stockId" th:field="*{stockId}" type="hidden"/>
        <h4 class="form-header h4">修改库存</h4>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">货位编号：</label>
                    <div class="col-sm-8">
                        <input name="cargoSpaceName" id="cargoSpaceName" th:field="*{cargoSpaceName}"   placeholder="请输入货位编号" style="width: 90%;float: left" autocomplete="off" class="form-control" type="text" maxlength="30"
                               required>

                        <input name="cargoSpaceId" id="cargoSpaceId" th:field="*{cargoSpaceId}"  placeholder="请输入货位编号"  style="display: none">
                        <a id="selectCargoSpace" class="btn btn-success" onclick="selectCargoSpace()"style="float: right" >
                            ...
                        </a>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">库存状态：</label>
                    <div class="col-sm-8">
                        <select name="stockStatus" th:field="*{stockStatus}" class="form-control"  id="stock_status" maxlength="30">
                            <option value="0" selected="true">正常</option>
                            <option value="1">冻结</option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">物料编号：</label>
                    <div class="col-sm-8">
                        <input name="productId" th:field="*{productId}" placeholder="请输入物料编号" class="form-control"autocomplete="off" type="text" maxlength="30"
                               required>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">物资状态：</label>
                    <div class="col-sm-8">
                        <select name="productStatus" th:field="*{productStatus}" class="form-control"  id="product_status" maxlength="30">
                            <option value="1">待检品</option>
                            <option value="2">合格品</option>
                            <option value="3">不合格品</option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">托盘条码：</label>
                    <div class="col-sm-8">
                        <input name="trayCode" th:field="*{trayCode}" placeholder="请输入托盘条码" class="form-control"autocomplete="off" readonly type="text" maxlength="30"
                               required>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">仓库名称：</label>
                    <div class="col-sm-8">
                        <select name="warehouseId" th:field="*{warehouseId}" class="form-control"  id="warehouse_id" maxlength="30">
                            <option value="01" selected="true">立体库</option>
                        </select>
                    </div>
                </div>
            </div>
<!--            <div class="col-sm-6">-->
<!--                <div class="form-group">-->
<!--                    <label class="col-sm-4 control-label is-required">批号：</label>-->
<!--                    <div class="col-sm-8">-->
<!--                        <input name="lotNo" th:field="*{lotNo}" placeholder="请输入批号" autocomplete="off" class="form-control" type="text" maxlength="30"-->
<!--                               required>-->
<!--                    </div>-->
<!--                </div>-->
<!--            </div>-->
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">数量：</label>
                    <div class="col-sm-8">
                        <input name="quantity" th:field="*{quantity}" placeholder="请输入数量" autocomplete="off" class="form-control" type="text" maxlength="30"
                               required>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">入库类型：</label>
                    <div class="col-sm-8">
                        <select name="inType" th:field="*{inType}" class="form-control"  id="in_type" maxlength="30">
                            <option value="1" selected="true">WMS建单入库</option>
                            <option value="2">ERP入库</option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
<!--            <div class="col-sm-6">-->
<!--                <div class="form-group">-->
<!--                    <label class="col-sm-4 control-label is-required">入库班组编号：</label>-->
<!--                    <div class="col-sm-8">-->
<!--                        <input name="inClassId" th:field="*{inClassId}" placeholder="请输入入库班组编号" autocomplete="off" class="form-control" type="text" maxlength="30"-->
<!--                               required>-->
<!--                    </div>-->
<!--                </div>-->
<!--            </div>-->

        </div>
<!--        <div class="row">-->
<!--            <div class="col-sm-6">-->
<!--                <div class="form-group">-->
<!--                    <label class="col-sm-4 control-label is-required">车间班组号：</label>-->
<!--                    <div class="col-sm-8">-->
<!--                        <input name="classgroupNumber" th:field="*{classgroupNumber}" placeholder="请输入车间班组编号" autocomplete="off" class="form-control" type="text" maxlength="30"-->
<!--                               required>-->
<!--                    </div>-->
<!--                </div>-->
<!--            </div>-->
<!--        </div>-->
    </form>
</div>

<th:block th:include="include :: footer" />
<th:block th:include="include :: select2-js" />
<script type="text/javascript">
    var prefix = ctx + "stock/stockCheck";


    function submitHandler() {
        var data = $("#form-user-edit").serializeArray();
        console.log(data)
        //TODO 如果沒有选择项目组（项目组为空 不允许提交）
        $.operate.save(prefix + "/updateStock", data);
    }

    /* 用户管理-修改-选择部门树 */
    function selectDeptTree() {
        var deptId = $.common.isEmpty($("#treeId").val()) ? "100" : $("#treeId").val();
        var url = ctx + "system/dept/selectDeptTree/" + deptId;
        var options = {
            title: '选择部门',
            width: "380",
            url: url,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero){
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        var body = layer.getChildFrame('body', index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        selectgroups();
        layer.close(index);
    }

    $(function() {
        $('#post').select2({
            placeholder: "请选择岗位",
            allowClear: true
        });
    })
    //分配项目组
    function selectgroups() {
        var deptId = $("#treeId").val();
        var url = ctx + "system/item/selectPrjgroupByDeptId/" + deptId;
        $.get(url, function (result) {
            console.log(result)
            var html = ""
            if(result.length>0){
                for (var i = 0; i < result.length; i++) {
                    html += "<option  value=" + result[i].prjgroupId + ">" + result[i].prjgroupName + "</option>"
                }
            }

            $("#prjGroup").html(html)
        })

    }

    // 选择货位
    function selectCargoSpace() {
        var options = {
            title: '选择货位',
            url : "/device/basCargoSpace/selectCargoSpace",
            callBack: getCargoSpace
        };
        $.modal.openOptions(options);
    }

    //关闭物资框
    function getCargoSpace(index, layero) {
        var row = layero.find("iframe")[0].contentWindow.getSelections();
        if (row.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            $.modal.close(index);
            $.modal.closeLoading();
            return;
        }
        $("#cargoSpaceId").val(row[0].cargo_space_id);
        $("#cargoSpaceName").val(row[0].cargo_space_name);
        $.modal.close(index);
        $.modal.closeLoading();
    }

</script>
</body>
</html>